package com.holic.spring.custom;

import com.holic.spring.custom.annotation.GraphQLMapping;
import org.apache.commons.lang3.StringUtils;

import java.lang.reflect.Method;

/**
 * @ClassName GraphQLMappingDefinition
 * @Description
 * @Author Neil
 * @Date 2024/11/15 10:54
 * @Version V1.0
 **/
public class GraphQLMappingDefinition {

    private Object bean;
    private Method method;
    private GraphQLMapping mapping;

    public GraphQLMappingDefinition(Object bean, Method method, GraphQLMapping mapping) {
        this.bean = bean;
        this.method = method;
        this.mapping = mapping;
    }

    public String getName() {
        return StringUtils.isBlank(mapping.field()) ? method.getName() : mapping.field();
    }

    public String getType(){
        return mapping.typeName();
    }

    public Object getBean() {
        return bean;
    }

    public Method getMethod() {
        return method;
    }

    public GraphQLMapping getMapping() {
        return mapping;
    }

    @Override
    public String toString(){
        return "GraphQLMappingDefinition { "
                    + "bean = " + bean.getClass()
                    + ", method = " + method.getName()
                    + ", mapping = " + getType() + ":" + getName()
                + " } ";
    }
}
